********************************************************************************
* Terrorism, perpetrators and polarization: Evidence from natural experiments 
* MAIN PAPER
* BY BOVE, DI LEO, EFTHYVOULOU & PICKARD
********************************************************************************

***Note for the replicator: Figure 4 cannot be replicated as it employs proprietary data from Twitter, so we cannot share the data. 
*The data employed in the analysis can be downloaded from Twitter, using the API: https://developer.twitter.com/en/docs/twitter-api

*Creates folders
mkdir "Figures"
mkdir "Tables"

*set scheme for figures' style
set scheme hp

*clear preexisting data
clear all

*turn graphic elaboration off
set graphics off

*open the dataset
use "Polarization_clean.dta", clear


/*
*********uncomment to generate codebook
quietly {
    log using Codebook_Polarization.txt, text replace
    noisily codebook
    log close
}
*/



*Define controls
glo controls "age age2 female i.work_clean i.education_clean i.marital_clean i.children_clean i.ethnicity_clean i.religion_clean"



********************************************************************************
*** FIGURE 1 
********************************************************************************

preserve

cap drop s_attacks_dista_labcon

*keep respondents from waves/attacks where the question under scrutiny was being aksed
bys wave attack_id: egen p_c=sd(post) if dista_labcon!=.
gen s_attacks_dista_labcon=(p_c>0 & p_c!=.)
drop p_c

*make sure the sample for which we calculate the histogram was interviewed around either an Islamic or Far-Right attack
qui reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
g farright_sample=e(sample)

qui reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
g islamic_sample=e(sample)

*keep if respondents were interviewed 
keep if farright_sample==1|islamic_sample==1

*center affective polarization around -0.5 to favour readability
replace dista_labcon=dista_labcon-0.5 if post==0

twoway (hist dista_labcon if post==0, width(1) fcolor(blue%30) color(blue%50)) ///
       (hist dista_labcon if post==1, width(1) fcolor(red%50) color(red)) ///
	   , xlabel(0(1)10) xtitle("") ytitle("") ///
	   legend(order(1 "Pre-attack" 2 "Post-attack") pos(6) row(1)) ///
	   plotregion(lc(black)) ///
	   title("All attacks") name("gr0", replace) aspect(1.35)

twoway (hist dista_labcon if post==0 & gname_small==2 & farright_sample==1, width(1) fcolor(blue%30) color(blue%50)) ///
       (hist dista_labcon if post==1 & gname_small==2 & farright_sample==1, width(1) fcolor(red%50) color(red)) ///
	   , xlabel(0(1)10) xtitle("") ytitle("") ///
	   legend(order(1 "Pre-attack" 2 "Post-attack") pos(6) row(1)) ///
	   plotregion(lc(black)) ///
	   title("Far-right attacks") name("gr1", replace) aspect(1.35)
	   
twoway (hist dista_labcon if post==0 & gname_small==3 & islamic_sample==1, width(1) fcolor(blue%30) color(blue%50)) ///
       (hist dista_labcon if post==1 & gname_small==3 & islamic_sample==1, width(1) fcolor(red%50) color(red)) ///
	   , xlabel(0(1)10) xtitle("") ytitle("") ///
	   legend(order(1 "Pre-attack" 2 "Post-attack") pos(6) row(1)) ///
	   plotregion(lc(black)) ///
	   title("Islamic attacks") name("gr2", replace) aspect(1.35)
	   	   
grc1leg gr0 gr1 gr2, ring(6) b1("Affective Polarization", yoffset(10)) l1("Density", xoffset(5)) row(1)
gr_edit .legend.DragBy 10 0
gr export "Figures/Figure_1.png", width(4000) replace

restore	 

 
********************************************************************************
*** Table 1 
********************************************************************************

est clear

*keep respondents from waves/attacks where the question under scrutiny was being aksed
bys wave attack_id: egen p_c=sd(post) if dista_labcon!=.
gen s_attacks_dista_labcon=(p_c>0 & p_c!=.)
drop p_c

*AGG. baseline
capture noisily eststo: reghdfe dista_labcon post if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "No", replace

*AGG. controls
capture noisily eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "Yes", replace

*AGG. lag 
capture noisily eststo: reghdfe dista_labcon post $controls lag_dista_labcon if s_attacks_dista_labcon, absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc controls "Yes", replace

*FAR-RIGHT baseline
capture noisily eststo: reghdfe dista_labcon post if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "Yes", replace
		estadd loc jihadi "No", replace
		estadd loc controls "No", replace

*FAR-RIGHT controls
capture noisily eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "Yes", replace
		estadd loc jihadi "No", replace
		estadd loc controls "Yes", replace

*FAR-RIGHT lag 
capture noisily eststo: reghdfe dista_labcon post $controls lag_dista_labcon if s_attacks_dista_labcon & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "Yes", replace
		estadd loc jihadi "No", replace
		estadd loc controls "Yes", replace

*ISLAMIC baseline
capture noisily eststo: reghdfe dista_labcon post if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "No", replace
		estadd loc jihadi "Yes", replace
		estadd loc controls "No", replace

*ISLAMIC controls
capture noisily eststo: reghdfe dista_labcon post $controls if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "No", replace
		estadd loc jihadi "Yes", replace
		estadd loc controls "Yes", replace
		
*ISLAMIC lag 
capture noisily eststo: reghdfe dista_labcon post $controls lag_dista_labcon if s_attacks_dista_labcon & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc rightwing "No", replace
		estadd loc jihadi "Yes", replace
		estadd loc controls "Yes", replace
		
esttab est* using "Tables/Table_1", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(post lag_dista_labcon) ///
order(post lag_dista_labcon) ///
varl(post "Post-attack" lag_dista_labcon "Lagged Affective Polarisation") ///
s(rightwing jihadi oslauawave controls N_clust r2 N, ///
label("Far-right attacks" "Islamic attacks" "LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 3 3 %9.0f 3 %9.0f)) ///
replace html nonotes	




 
********************************************************************************
*** FIGURE 2
********************************************************************************

cap drop s_attacks_dista_labcon

foreach y in dista_labcon {

	*keep respondents from waves/attacks where the question under scrutiny was being aksed
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c
	
	est clear
	
	*ALL ATTACKS
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' , absorb(oslauawave, save) vce(cluster oslaua)
		loc beta=_b[post]

	*FAR-RIGHT
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1=e(N)
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*SINGLE FAR-RIGHT
	loc attacks  "16jun2016 19jun2017"
	foreach attack of local attacks {
		capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & attack_date==td(`attack') , absorb(oslauawave, save) vce(cluster oslaua)
		loc n1_`attack'=e(N)
		capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & attack_date==td(`attack') , absorb(oslauawave, save) vce(cluster oslaua)
	}

	*ISLAMIC
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2=e(N)
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	*SINGLE ISLAMIC
	loc attacks  "22may2017 29nov2019"
	foreach attack of local attacks {
		capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & attack_date==td(`attack') , absorb(oslauawave, save) vce(cluster oslaua)
		loc n2_`attack'=e(N)
		capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & attack_date==td(`attack') , absorb(oslauawave, save) vce(cluster oslaua)
	}

	coefplot ///
	(est2, offset(0.2)   keep(post) rename(post = "Far-right Attacks") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(-0.2)  keep(post) rename(post = "Far-right Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(0.2)   keep(post) rename(post = "Jo Cox Murder") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(-0.2)  keep(post) rename(post = "Jo Cox Murder") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est6, offset(0.2)   keep(post) rename(post = "Finsbury Park Attack") msymbol(circle)  mcolor(black) ciopts(lcolor(black black))) ///
	(est7, offset(-0.2)  keep(post) rename(post = "Finsbury Park Attack") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est8, offset(0.2)   keep(post) rename(post = "Islamic Attacks") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est9, offset(-0.2)  keep(post) rename(post = "Islamic Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est10, offset(0.2)  keep(post) rename(post = "Manchester Arena Bombing") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est11, offset(-0.2) keep(post) rename(post = "Manchester Arena Bombing") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est12, offset(0.2)  keep(post) rename(post = "London Bridge Stabbing") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est13, offset(-0.2) keep(post) rename(post = "London Bridge Stabbing") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Jo Cox Murder" = "N = `n1_16jun2016'" "Finsbury Park Attack" = "N = `n1_19jun2017'" ///
	"Islamic Attacks" = "N = `n2'" "Manchester Arena Bombing" = "N = `n2_22may2017'" "London Bridge Stabbing" = "N = `n2_29nov2019'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.4(0.2)0.4) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(6, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))
	
	gr export "Figures/Figure_2.png", width(4000) replace
	
	}	


	
********************************************************************************
*** Table 2 									
********************************************************************************

cap drop s_attacks_*

*keep respondents from waves/attacks where the question under scrutiny was being aksed
bys wave attack_id: egen post_sd=sd(post) if likecon!=.
gen s_attacks_likecon=(post_sd>0 & post_sd!=.)
drop post_sd
*keep respondents from waves/attacks where the question under scrutiny was being aksed
bys wave attack_id: egen post_sd=sd(post) if likelab!=.
gen s_attacks_likelab=(post_sd>0 & post_sd!=.)
drop post_sd

*Create tables 
qui { // Table

// Panel A - Far-right
est clear

* imputed conservatives -> like con
capture noisily eststo: reghdfe likecon post $controls if s_attacks_likecon & gname_small==2  & lag_partyid_imp_con==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Con", replace
		estadd loc controls "Yes", replace
		
* imputed conservatives -> like lab
capture noisily eststo: reghdfe likelab post $controls if s_attacks_likelab & gname_small==2  & lag_partyid_imp_con==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Con", replace
		estadd loc controls "Yes", replace
		
* imputed lab -> like con
capture noisily eststo: reghdfe likecon post $controls if s_attacks_likecon & gname_small==2  & lag_partyid_imp_lab==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Lab", replace
		estadd loc controls "Yes", replace
		
* imputed lab -> like lab
capture noisily eststo: reghdfe likelab post $controls if s_attacks_likelab & gname_small==2  & lag_partyid_imp_lab==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Lab", replace
		estadd loc controls "Yes", replace
		
* imputed Green/Liberals -> like con
capture noisily eststo: reghdfe likecon post $controls if s_attacks_likecon & gname_small==2  & lag_partyid_imp_greenlib==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Green & LD", replace
		estadd loc controls "Yes", replace
		
* imputed Green/Liberals -> like lab
capture noisily eststo: reghdfe likelab post $controls if s_attacks_likelab & gname_small==2  & lag_partyid_imp_greenlib==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Green & LD", replace
		estadd loc controls "Yes", replace
		
esttab est* using "Tables/Table_2a", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(post) ///
order(post) ///
varl(post "Post-attack") ///
s(sample oslauawave controls N_clust r2 N, ///
label("Partisan identity" "LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 3 %9.0f 3 %9.0f)) ///
replace html nonotes	


// Panel B - Islamic
est clear

* imputed cons -> like con
capture noisily eststo: reghdfe likecon post $controls if s_attacks_likecon & gname_small==3  & lag_partyid_imp_con==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Con", replace
		estadd loc controls "Yes", replace
		
* imputed cons -> like lab
capture noisily eststo: reghdfe likelab post $controls if s_attacks_likelab & gname_small==3  & lag_partyid_imp_con==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Con", replace
		estadd loc controls "Yes", replace
		
* imputed lab -> like con
capture noisily eststo: reghdfe likecon post $controls if s_attacks_likecon & gname_small==3  & lag_partyid_imp_lab==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Lab", replace
		estadd loc controls "Yes", replace
		
* imputed lab -> like lab
capture noisily eststo: reghdfe likelab post $controls if s_attacks_likelab & gname_small==3  & lag_partyid_imp_lab==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Lab", replace
		estadd loc controls "Yes", replace
		
* imputed Green/Liberals -> like con
capture noisily eststo: reghdfe likecon post $controls if s_attacks_likecon & gname_small==3  & lag_partyid_imp_greenlib==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Green & LD", replace
		estadd loc controls "Yes", replace
		
* imputed Green/Liberals -> like lab
capture noisily eststo: reghdfe likelab post $controls if s_attacks_likelab & gname_small==3  & lag_partyid_imp_greenlib==1 , absorb(oslauawave, save) vce(cluster oslaua)
		estadd loc oslauawave "Yes", replace							
		estadd loc sample "Green & LD", replace
		estadd loc controls "Yes", replace
		

esttab est* using "Tables/Table_2b", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(post) ///
order(post) ///
varl(post "Post-attack") ///
s(sample oslauawave controls N_clust r2 N, ///
label("Partisan identity" "LAD $\times$ Wave FEs" "Controls" "No. of LADs" "R-squared" "Observations") ///
fmt(3 3 3 %9.0f 3 %9.0f)) ///
replace html nonotes	

} 
 
 

 

********************************************************************************
*** FIGURE 3
********************************************************************************

drop s_attacks_*

foreach y in mii_terror {

	*keep respondents from waves/attacks where the question under scrutiny was being aksed
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	est clear
	
	*ALL ATTACKS
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' , absorb(oslauawave, save) vce(cluster oslaua)
		loc beta=_b[post]

	*Far-right
	*controls 
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	coefplot ///
	(est2, offset(0.2)  keep(post) rename(post = "Far-right Attacks") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(-0.2) keep(post) rename(post = "Far-right Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(0.2)  keep(post) rename(post = "Islamic Attacks") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est5, offset(-0.2) keep(post) rename(post = "Islamic Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Far-right Attacks" = "N = `n1'" "Islamic Attacks" = "N = `n2'") ///
	yscale(alt axis(2)) ///
	xlabel(-0.05(0.05)0.3) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(2, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))
	
	gr export "Figures/Figure_3.png", width(4000) replace

	}	





********************************************************************************
*** FIGURE 4
********************************************************************************

/*
preserve 

*open the dataset
import delimited "tweets_immig.csv", clear 

*distinguish attack types
g type="Far-right" if attack=="Jo Cox" | attack=="Finsbury Park"
replace type="Islamic" if type==""

*collapse by attack and whether in the 3days pre-post attack
collapse (mean) sent_fear=fear sent_anger=anger sent_sadness=sadness (semean) se_fear=fear se_anger=anger se_sadness=sadness, by(type post)

reshape long sent_ se_, i(type post) j(sentiment) string

*rename sentiments
replace sentiment="Anger" if sentiment=="anger"
replace sentiment="Sadness" if sentiment=="sadness"
replace sentiment="Fear" if sentiment=="fear"

*standard errors
g se_up=sent_+se_*1.65 // 10%
g se_lo=sent_-se_*1.65 // 10%

loc i=1
foreach type in "Far-right" "Islamic" { 

g gr_pos=.
replace gr_pos=0.5 if type=="`type'" & sentiment=="Anger" & post=="Pre-attack"
replace gr_pos=1.5 if type=="`type'" & sentiment=="Anger" & post=="Post-attack"
replace gr_pos=3.5 if type=="`type'" & sentiment=="Sadness" & post=="Pre-attack"
replace gr_pos=4.5 if type=="`type'" & sentiment=="Sadness" & post=="Post-attack"
replace gr_pos=6.5 if type=="`type'" & sentiment=="Fear" & post=="Pre-attack"
replace gr_pos=7.5 if type=="`type'" & sentiment=="Fear" & post=="Post-attack"

twoway ///
(bar sent_ gr_pos if post=="Pre-attack" & type=="`type'", fcolor(blue%30) color(blue)) ///
(bar sent_ gr_pos if post=="Post-attack" & type=="`type'", fcolor(red%50) color(red)) ///
(rcap se_up se_lo gr_pos, lc(black)) ///
, xlabel(1 "Anger" 4 "Sadness" 7 "Fear") ///
yscale(range(0 0.09)) ylabel(0 0.03 0.06 0.09 0.12) ///
ytitle("") xtitle("") title("`type' Attacks") ///
plotregion(lc(black)) ylabe(, nogrid) ///
legend(order(1 "Pre-attack" 2 "Post-attack") pos(6) row(1)) ///
name("gr_`i'", replace)

drop gr_pos

loc i=`i'+1

}

grc1leg gr_1 gr_2, ring(4) b1("Sentiment") l1("Mean value")
gr export "Figures/Figure_4.png", width(4000) replace

restore
*/



********************************************************************************
*** FIGURE 5 
********************************************************************************

drop s_attacks_* 

est clear 

foreach y in immigcultural immigecon {

	*keep respondents from waves/attacks where the question under scrutiny was being aksed
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c

	*NOTE: FAR-RIGHT ATTACKS ONLY
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1_`y'=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	
	}

	coefplot ///
	(est1, offset(0.2)  keep(post) rename(post = "Immigration Enriches Cultural Life") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est2, offset(-0.2) keep(post) rename(post = "Immigration Enriches Cultural Life") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	(est3, offset(0.2)  keep(post) rename(post = "Immigration Good for the Economy") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
	(est4, offset(-0.2) keep(post) rename(post = "Immigration Good for the Economy") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) ///
	xtitle("Coefficient of 'Post-attack'") ///
	groups("Immigration Enriches Cultural Life" = "N = `n1_immigcultural'" "Immigration Good for the Economy" = "N = `n1_immigecon'") ///
	xlabel(-0.4(0.2)0.4) ///
	yscale(alt axis(2)) ///
	grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
	plotregion(lc(black)) ///
	xline(0, lc(red) lp(dash)) ///
	yline(2, lc(gs12%60) lp(solid) lw(medthick)) ///
	legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))	

	gr export "Figures/Figure_5.png", width(4000) replace
	
	
	
	
********************************************************************************
*** FIGURE 6
********************************************************************************

cap drop s_attacks_* 

est clear

foreach y in likeukip {

	*keep respondents from waves/attacks where the question under scrutiny was being aksed
	bys wave attack_id: egen p_c=sd(post) if `y'!=.
	gen s_attacks_`y'=(p_c>0 & p_c!=.)
	drop p_c
	
	*FAR-RIGHT
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n1_`y'_right=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==2 , absorb(oslauawave, save) vce(cluster oslaua)

	*ISLAMIC
	*controls
	capture noisily eststo: reghdfe `y'  post $controls if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)
	loc n2_`y'_islamic=e(N)
	*no controls
	capture noisily eststo: reghdfe `y'  post if s_attacks_`y' & gname_small==3 , absorb(oslauawave, save) vce(cluster oslaua)

	}
	
coefplot ///
(est1, offset(0.2)  keep(post) rename(post = "Far-right Attacks") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
(est2, offset(-0.2) keep(post) rename(post = "Far-right Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
(est3, offset(0.2)  keep(post) rename(post = "Islamic Attacks") msymbol(circle) mcolor(black) ciopts(lcolor(black black))) ///
(est4, offset(-0.2) keep(post) rename(post = "Islamic Attacks") msymbol(X) msize(large) mcolor(black) ciopts(lcolor(black black))) ///
, levels(95 90) ///
xtitle("Coefficient of 'Post-attack'") ///
groups("Far-right Attacks" = "N = `n1_likeukip_right'" "Islamic Attacks" = "N = `n2_likeukip_islamic'") ///
xlabel(-0.4(0.2)0.4) ///
yscale(alt axis(2)) ///
grid(between glpattern(dash) glwidth(*2) glcolor(white) nogextend) ///
plotregion(lc(black)) ///
xline(0, lc(red) lp(dash)) ///
yline(2, lc(gs12%60) lp(solid) lw(medthick)) ///
legend(order(3 "Controls" 6 "No Controls") pos(6) row(1))	
	
gr export "Figures/Figure_6.png", width(4000) replace

	
